package com.ruoyi.mall.sms.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.sms.domain.SmsFlashPromotionSession;
import com.ruoyi.mall.sms.service.ISmsFlashPromotionSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 限时购场次Controller
 *
 * @author xuxing
 * @date 2021-02-09
 */
@RestController
@RequestMapping("/sms/flashPromotionSession")
public class SmsFlashPromotionSessionController extends BaseController
{
    @Autowired
    private ISmsFlashPromotionSessionService smsFlashPromotionSessionService;

    /**
     * 查询限时购场次列表
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionSession:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsFlashPromotionSession smsFlashPromotionSession)
    {
        startPage();
        List<SmsFlashPromotionSession> list = smsFlashPromotionSessionService.selectSmsFlashPromotionSessionList(smsFlashPromotionSession);
        return getDataTable(list);
    }

    /**
     * 导出限时购场次列表
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionSession:export')")
    @Log(title = "限时购场次", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmsFlashPromotionSession smsFlashPromotionSession)
    {
        List<SmsFlashPromotionSession> list = smsFlashPromotionSessionService.selectSmsFlashPromotionSessionList(smsFlashPromotionSession);
        ExcelUtil<SmsFlashPromotionSession> util = new ExcelUtil<SmsFlashPromotionSession>(SmsFlashPromotionSession.class);
        return util.exportExcel(list, "flashPromotionSession");
    }

    /**
     * 获取限时购场次详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionSession:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsFlashPromotionSessionService.selectSmsFlashPromotionSessionById(id));
    }

    /**
     * 新增限时购场次
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionSession:add')")
    @Log(title = "限时购场次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession)
    {
        return toAjax(smsFlashPromotionSessionService.insertSmsFlashPromotionSession(smsFlashPromotionSession));
    }

    /**
     * 修改限时购场次
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionSession:edit')")
    @Log(title = "限时购场次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession)
    {
        return toAjax(smsFlashPromotionSessionService.updateSmsFlashPromotionSession(smsFlashPromotionSession));
    }

    /**
     * 删除限时购场次
     */
    @PreAuthorize("@ss.hasPermi('sms:flashPromotionSession:remove')")
    @Log(title = "限时购场次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsFlashPromotionSessionService.deleteSmsFlashPromotionSessionByIds(ids));
    }
}
